package com.hp.attendance.service;

import com.hp.attendance.dao.AttendanceDao;
import com.hp.attendance.entity.Attendance;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.dto.AttendanceDto;
import com.hp.attendance.entity.dto.LateDTO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AttendanceService {
    private AttendanceDao attendanceDao = new AttendanceDao();

    public List<AttendanceDto> listAttendance() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        ArrayList<AttendanceDto> List = new ArrayList<AttendanceDto>();
        java.util.List<Attendance> listAttendance = attendanceDao.listAttendance();
        for (Attendance attendance : listAttendance) {
            AttendanceDto attendanceDto = new AttendanceDto();
            Integer employee_number = attendance.getEmployee_number();
            Employee employee = attendanceDao.employeeName(employee_number);
            attendanceDto.setAttendance(attendance);
            attendanceDto.setEmployee(employee);
            List.add(attendanceDto);
        }
        return List;
    }

    //查询考勤记录
    public List<Attendance> listAttendance2() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return attendanceDao.listAttendance();
    }

    //查询员工迟到次数
    public List<LateDTO> getLate() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return attendanceDao.getLate();
    }
}